package com.woniuxy.ptapp.common.util;

import com.woniuxy.commons.util.Result;
import com.woniuxy.ptapp.common.exception.EnumExceptionCode;
import com.woniuxy.ptapp.common.exception.WoniuxyException;
import com.woniuxy.userapp.client.CoachClient;
import com.woniuxy.userapp.client.StudentClient;
import com.woniuxy.userapp.client.VenueClient;
import com.woniuxy.userapp.client.param.CoachInfo;
import com.woniuxy.userapp.client.param.StudentInfo;
import com.woniuxy.userapp.client.param.VenueInfo;
import org.checkerframework.checker.units.qual.C;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class FinMessageIdByAccountId {

    @Resource
    VenueClient venueClient;
    @Resource
    CoachClient coachClient;
    @Resource
    StudentClient studentClient;
    public Integer findVenueId(Integer venueAccountId){

        Result<VenueInfo> venueByAccountId = venueClient.findVenueByAccountId(venueAccountId);
        if(venueByAccountId==null||venueByAccountId.getCode()==500||venueByAccountId.getData()==null){
            throw new WoniuxyException(EnumExceptionCode.ThereIsNoVenue.getCode(),EnumExceptionCode.ThereIsNoVenue.getMessage());
        }
        return venueByAccountId.getData().getId();
    }

    public Integer findCoachId(Integer coachAccountId){

        Result<CoachInfo> coachByAccountId = coachClient.findCoachByAccountId(coachAccountId);
        if(coachByAccountId==null||coachByAccountId.getCode()==500||coachByAccountId.getData()==null){
            throw new WoniuxyException(EnumExceptionCode.ThereIsNoCoach.getCode(),EnumExceptionCode.ThereIsNoCoach.getMessage());
        }
        return coachByAccountId.getData().getId();
    }

    public Integer findStudentId(Integer studentAccountId){

        Result<StudentInfo> studentByAccountId = studentClient.findStudentByAccountId(studentAccountId);
        if(studentByAccountId==null||studentByAccountId.getCode()==500||studentByAccountId.getData()==null){
            throw new WoniuxyException(EnumExceptionCode.ThereIsNoStudent.getCode(),EnumExceptionCode.ThereIsNoStudent.getMessage());
        }
        return studentByAccountId.getData().getId();
    }
}
